﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Brjnk.Common;
using Brjnk.GpxExplorer.ViewModel;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for GeoObjectsPicker.xaml
    /// </summary>
    public partial class GeoObjectsPicker : UserControl, INotifyPropertyChanged
    {
        public GeoObjectsPicker()
        {
            InitializeComponent();
        }

        private IEnumerable<CheckListItem<WaypointVM>> waypoints = new List<CheckListItem<WaypointVM>>();

        public IEnumerable<CheckListItem<WaypointVM>> Waypoints
        {
            get { return waypoints.ToList(); }
            set { waypoints = value; OnPropertyChanged("Waypoints"); }
        }

        private IEnumerable<CheckListItem<RouteVM>> routes = new List<CheckListItem<RouteVM>>();

        public IEnumerable<CheckListItem<RouteVM>> Routes
        {
            get { return routes; }
            set { routes = value; OnPropertyChanged("Routes"); }
        }

        private IEnumerable<CheckListItem<TrackVM>> tracks = new List<CheckListItem<TrackVM>>();

        public IEnumerable<CheckListItem<TrackVM>> Tracks
        {
            get { return tracks.ToList(); }
            set { tracks = value; OnPropertyChanged("Tracks"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void wpAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (var wp in waypoints)
                wp.IsChecked = true;
        }

        private void wpNothing_Click(object sender, RoutedEventArgs e)
        {
            foreach (var wp in waypoints)
                wp.IsChecked = false;
        }

        private void gcAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (var wp in waypoints.Where(p => p.Object.Source.Geocache != null))
                wp.IsChecked = true;
        }

        private void gcNothing_Click(object sender, RoutedEventArgs e)
        {
            foreach (var wp in waypoints.Where(p => p.Object.Source.Geocache != null))
                wp.IsChecked = false;
        }

        private void rAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (var r in routes)
                r.IsChecked = true;
        }

        private void rNothing_Click(object sender, RoutedEventArgs e)
        {
            foreach (var r in routes)
                r.IsChecked = false;
        }

        private void tAll_Click(object sender, RoutedEventArgs e)
        {
            foreach (var t in tracks)
                t.IsChecked = true;
        }

        private void tNothing_Click(object sender, RoutedEventArgs e)
        {
            foreach (var t in tracks)
                t.IsChecked = false;
        }
    }
}